package com.songjiakang.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;



import com.github.pagehelper.PageInfo;
import com.songjiakang.entity.Drom;
import com.songjiakang.entity.Floor;
import com.songjiakang.entity.Record;
import com.songjiakang.entity.Role;
import com.songjiakang.entity.Student;
import com.songjiakang.service.DromService;

@Controller
public class DromController {
	@Autowired
	private DromService service;
	//登录
	@RequestMapping("tologin")
	public String tologin(){
		return "login";
	}
	//登录验证
	@RequestMapping("login")
	@ResponseBody
	public boolean login(Student student,HttpServletRequest request){
		Student student2=service.login(student);
		if (student2==null) {
			return false;
		}else {
			request.getSession().setAttribute("name", student2);
			return true;
		}
	}
	//学生列表
	@RequestMapping("list")
	public String list(HttpServletRequest request,Model model,@RequestParam(defaultValue="1")Integer pageNum,@RequestParam(defaultValue="2")Integer pageSize,String name,String hao){
		Student student = (Student) request.getSession().getAttribute("name");
		Role role = student.getRole();
		Integer roleInteger = role.getinteger();
		if (roleInteger==0) {
			List<Record> list=service.list0(student);
			model.addAttribute("list", list);
			return "list";
		}
		PageInfo info = service.list1(pageNum, pageSize,hao,name);
		model.addAttribute("info", info);
		return "list2";
	}
	//详情
	@RequestMapping("detail")
	public String detail(Integer id,Model model){
		Record record=service.shang(id);
		model.addAttribute("record", record);
		List<Record> list=service.xia(id);
		model.addAttribute("list", list);
		return "detail";
	}
	//跳转到调室页面
	@RequestMapping("tiao")
	public String tiao(Model model){
		List<Student> list=service.getstudent();
		model.addAttribute("list", list);
		return "tiao";
	}
	//查询楼
	@RequestMapping("floor")
	@ResponseBody
	public List<Floor> floor(){
		return service.floor();
	}
	//查询楼下的宿舍号
	@RequestMapping("drom")
	@ResponseBody
	public List<Drom> drom(Integer id){
		
		return service.drom(id);
	}
	//修改
	@RequestMapping("update")
	public String update(String name,Integer id){
		System.err.println(name+"  "+id);
		return "list";
	}
}
